home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / text / hyper / GetHelp.lha / GetHelp / GetHelp.rexx < prev    next >
OS/2 REXX Batch file  |  1999-02-11  |  6KB  |  248 lines

  1. /* GetHelp.rexx - Opens html help file on URL link from a browser
  2. ** $VER: GetHelp.rexx 0.9 (10.2.99) by B.Rogers <bsrogers@cobweb.com.au>
  3. ** Refer to the documentation for usage, version history etc.
  4. */
  5.  
  6. /**************************************
  7. ** Set up constants
  8. */
  9.  
  10. /* Default html file if no arguments */
  11. default_url='file://localhost/Help:Amiga_help.help'
  12.  
  13. /* Debug flag (1=true) */
  14. DeBug=0
  15.  
  16. /**************************************
  17. ** Main program
  18. */
  19.  
  20. OPTIONS RESULTS
  21. OPTIONS FAILAT 21
  22. ADDRESS COMMAND
  23.  
  24. PARSE ARG help_url
  25.  
  26. /* remove any nastly quotes from help_url
  27. ** ie rx GetHelp "Help:ag2html.help"
  28. */
  29.  
  30. help_url = STRIP(help_url,'B','"')
  31.  
  32. IF debug=1 THEN SAY help_url
  33.  
  34. /*
  35. ** options are:
  36. ** 1.  Initial call for Help (default html page)
  37. ** 2.  Call for a specific help file
  38. ** 3.  Call to exit Help
  39. **
  40. */
  41.  
  42. SELECT
  43.  
  44.   WHEN help_url='QUIT' THEN DO
  45.     IF debug=1 THEN SAY 'Quit Message...'
  46.     CALL Clean_Up
  47.     EXIT
  48.   END
  49.  
  50.   WHEN help_url="" THEN DO
  51.  
  52.    /* prepare to display default html file */
  53.    url=default_url
  54.    first_time=1
  55.  
  56.    /* create T:Help directory
  57.    ** - this also flags that the help function has been called
  58.    */
  59.    IF ~EXISTS("T:Help") THEN DO
  60.      IF debug=1 THEN SAY 'Initialising T:Help directory'
  61.      'makedir' "T:Help"
  62.    END
  63.    IF debug=1 THEN SAY "Displaying default help page..."
  64.  
  65.   END
  66.  
  67.   OTHERWISE url = get_url(help_url)
  68.  
  69. END
  70.  
  71. /*
  72. ** Display url using Openurl
  73. */
  74.  
  75. IF debug=1 THEN SAY 'Displaying file...'url
  76. openurl url
  77.  
  78. /* user has ended help session */
  79. IF first_time=1 THEN DO
  80.   SAY 'All done! Exiting...'
  81.   CALL Clean_up
  82. END
  83.  
  84. /* exit gethelp */
  85. EXIT
  86.  
  87.  
  88. /**********************************************************
  89. ** get a correctly formatted url ready to feed to a browser
  90. */
  91.  
  92. get_url:
  93.  
  94.   PARSE ARG help_url
  95.  
  96.   /*
  97.   ** check for file://localhost/, file:///, http:// or ftp:// paths
  98.   */
  99.   pos_local = INDEX(help_url,"file://localhost/")
  100.   IF pos_local>0 THEN DO
  101.     help_url=RIGHT(help_url,LENGTH(help_url)-17)
  102.     IF ~EXISTS(help_url) THEN DO
  103.       clean_up
  104.       EXIT 10
  105.     END
  106.     IF debug=1 THEN DO
  107.       SAY "Yep, its a local file [file://localhost/]"
  108.       SAY help_url
  109.     END
  110.   END
  111.   ELSE DO
  112.     pos_local = INDEX(help_url,"file:///")
  113.     IF pos_local>0 THEN DO
  114.       help_url=RIGHT(help_url,LENGTH(help_url)-8)
  115.       IF ~EXISTS(help_url) THEN DO
  116.         clean_up
  117.         EXIT 10
  118.       END
  119.       IF debug=1 THEN DO
  120.         SAY "Yep, its a local file [file:///]"
  121.         SAY help_url
  122.       END
  123.     END
  124.     ELSE DO
  125.       pos_http = INDEX(help_url,"http:")
  126.       pos_ftp = INDEX(help_url,"ftp:")
  127.       IF pos_http>0 OR pos_ftp>0 THEN DO
  128.         SAY "Yep, it's online - future capability enhancement!"
  129.         clean_up
  130.         EXIT
  131.       END
  132.     END
  133.   END
  134.  
  135.   /*
  136.   ** parse any assigns or devices in path
  137.   */
  138.   pos_assign = INDEX(help_url,":")
  139.   IF poss_assign>0 THEN DO
  140.     path_assign = LEFT(help_url,pos_assign)
  141.     /* trim path_assign from help_url */
  142.     help_path = RIGHT(help_url,LENGTH(help_url)-pos_assign)
  143.     IF debug=1 THEN DO
  144.       SAY "Help path="help_path
  145.       SAY "Assign path="path_assign
  146.     END
  147.   END
  148.  
  149.   /*
  150.   ** now check for / markers
  151.   */
  152.   pos_dir = LASTPOS("/",help_path)
  153.   IF pos_dir>0 THEN DO
  154.     path_dir = LEFT(help_path,pos_dir)
  155.     help_file = RIGHT(help_path,LENGTH(help_path)-pos_dir)
  156.   END
  157.   ELSE DO
  158.     /* there were no / markers! */
  159.     help_file = help_path
  160.   END
  161.  
  162.   /* remove .html suffix */
  163.   help_file_name = SUBSTR(help_file,1,LENGTH(help_file)-5)
  164.  
  165.   /* debug info */
  166.   IF debug=1 THEN DO
  167.     SAY "path dir="path_dir
  168.     SAY "help_file="help_file
  169.   END
  170.  
  171.   /* set up help directory in T: and first file to show */
  172.   help_directory = "T:Help/"help_file_name
  173.   help_html = help_file_name".html"
  174.  
  175.   IF debug=1 THEN DO
  176.     SAY "help_directory="help_directory
  177.     SAY "help_html="help_html
  178.   END
  179.  
  180.   /*
  181.   ** extract html files if not already cached
  182.   */
  183.   IF ~EXISTS(help_directory) THEN
  184.     DO
  185.       /* confirm we have a T:Help directory */
  186.       IF ~EXISTS("T:Help") THEN DO
  187.         IF debug=1 THEN SAY 'NOTE - a browser has directly accessed a help file!'
  188.         'makedir' "T:Help"
  189.         /* spawn process to monitor Browser quit */
  190.         'RUN >NIL: SYS:Rexxc/rx GetHelp.rexx QUIT'
  191.       END
  192.  
  193.       /* create help topic subdirectory */
  194.       'makedir' help_directory
  195.  
  196.       IF debug=1 THEN 'lha -I -X x "'help_url'"' help_directory'/'
  197.       ELSE 'lha -I -X -q x "'help_url'"' help_directory'/'
  198.     END
  199.  
  200.   /*
  201.   ** select main.html if available, else default to <help_html>.html
  202.   */
  203.  
  204.   IF EXISTS(help_directory"/main.html") THEN help_html = "main.html"
  205.  
  206.   /*
  207.   ** if neither option found, we have an error!
  208.   */
  209.   IF ~EXISTS(help_directory"/"help_html) THEN DO
  210.     ADDRESS COMMAND
  211.     msg = '"Could not find main.html or 'help_html'..."'
  212.     'requestchoice' 'Browser' msg 'Investigate'
  213.     CALL clean_up
  214.     EXIT
  215.   END
  216.  
  217.   /* tell browser where first file will be.. */
  218.   url = "file:///"help_directory"/"help_html
  219.  
  220. RETURN url
  221.  
  222. /************************************************
  223. ** clean up and exit on-line help
  224. */
  225.  
  226. clean_up:
  227.  
  228.   ADDRESS COMMAND
  229.  
  230.   /* give browser time to appear! */
  231.   'WAIT' 5
  232.  
  233.   /* this line is ugly, but with OpenUrl have no identified way of knowing which browser is in use..*/
  234.   DO FOREVER
  235.     IF (~SHOW('P','IBROWSE')&~SHOW('P','VOYAGER')&~SHOW('P','AWEB.1')&~SHOW('P','MOREHTML')) THEN BREAK
  236.     'WAIT' 5
  237.   END
  238.  
  239.   IF debug=1 THEN SAY 'Deleting T: files...'
  240.  
  241.   /* remove T: files */
  242.   'delete' ">NIL: T:Help ALL"
  243.   'delete' ">NIL: T:temp#?"
  244.   'delete' ">NIL: T:Command#?"
  245.   IF debug=1 THEN SAY 'Finished!'
  246.  
  247. RETURN
  248.